import { expect } from "jsr:@std/expect";
import { buildQuery } from "./main.ts";

interface UserDTO {
  name: string;
  age: number;
  email: string;
  address: string;
}

Deno.test("OpHandler value require", () => {
  expect(() =>
    buildQuery<UserDTO>({
      fields: [
        {
          label: "name",
          op: "eq",
        },
      ],
    })
  ).toThrow("name is required");
});

Deno.test("OpHandler not support array", () => {
  expect(() =>
    buildQuery<UserDTO>({
      fields: [
        {
          label: "name",
          op: "eq",
          value: ["a", "b"],
        },
      ],
    })
  ).toThrow("eq is not support array");
});

Deno.test("OpHandler[tuple] value require", () => {
  expect(() =>
    buildQuery<UserDTO>({
      fields: [
        ["name", "eq"],
      ],
    })
  ).toThrow("name is required");
});

Deno.test("OpHandler[tuple] not support array", () => {
  expect(() =>
    buildQuery<UserDTO>({
      fields: [["name", "eq", ["a", "b"]]],
    })
  ).toThrow("eq is not support array");
});

Deno.test("BtHandler value must be 2", () => {
  expect(() =>
    buildQuery<UserDTO>({
      fields: [
        {
          label: "name",
          op: "bt",
        },
      ],
    })
  ).toThrow("bt must has two values");
});

Deno.test("BtHandler value must be 2 (2)", () => {
  expect(() =>
    buildQuery<UserDTO>({
      fields: [
        {
          label: "name",
          op: "bt",
          value: "1",
        },
      ],
    })
  ).toThrow("bt must has two values");
});

Deno.test("BtHandler[tuple] value must be 2", () => {
  expect(() =>
    buildQuery<UserDTO>({
      fields: [["name", "bt"]],
    })
  ).toThrow("bt must has two values");
});

Deno.test("BtHandler[tuple] value must be 2 (2)", () => {
  expect(() =>
    buildQuery<UserDTO>({
      fields: [["name", "bt", "a"]],
    })
  ).toThrow("bt must has two values");
});

Deno.test("NValueHandler value must greater than 1", () => {
  expect(() =>
    buildQuery<UserDTO>({
      fields: [
        {
          label: "name",
          op: "ol",
        },
      ],
    })
  ).toThrow("value length must greater then 1");
});

Deno.test("NValueHandler value must greater than 1 (2)", () => {
  expect(() =>
    buildQuery<UserDTO>({
      fields: [
        {
          label: "name",
          op: "ol",
          value: ["1"],
        },
      ],
    })
  ).toThrow("value length must greater then 1");
});

Deno.test("NValueHandler[Tuple] value must greater than 1", () => {
  expect(() =>
    buildQuery<UserDTO>({
      fields: [["name", "ol"]],
    })
  ).toThrow("value length must greater then 1");
});

Deno.test("NValueHandler[tuple] value must greater than 1 (2)", () => {
  expect(() =>
    buildQuery<UserDTO>({
      fields: [["name", "ol", "1"]],
    })
  ).toThrow("value length must greater then 1");
});

Deno.test("ZeroValueHandler value must be undefined", () => {
  expect(() =>
    buildQuery<UserDTO>({
      fields: [
        {
          label: "name",
          op: "nl",
          value: 123,
        },
      ],
    })
  ).toThrow("value must be undefined");
});

Deno.test("ZeroValueHandler[Tuple] value must be undefined", () => {
  expect(() =>
    buildQuery<UserDTO>({
      fields: [["name", "nl", 123]],
    })
  ).toThrow("value must be undefined");
});
